package com.bysj.yqsht.service.impl;

import com.bysj.yqsht.bean.CheckTeacher;
import com.bysj.yqsht.bean.Teacher;
import com.bysj.yqsht.bean.TeacherExample;
import com.bysj.yqsht.bean.extend.TeacherExtend;
import com.bysj.yqsht.dao.CheckTeacherMapper;
import com.bysj.yqsht.dao.TeacherMapper;
import com.bysj.yqsht.dao.extend.CheckTeacherExtendMapper;
import com.bysj.yqsht.dao.extend.TeacherExtendMapper;
import com.bysj.yqsht.service.ITeacherService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ITeacherServiceImpl implements ITeacherService {
    @Resource
    private TeacherMapper teacherMapper;

    @Resource
    private TeacherExtendMapper teacherExtendMapper;

    @Resource
    private CheckTeacherExtendMapper checkTeacherExtendMapper;

    @Override
    public List<Teacher> findAll() {
        TeacherExample teacherExample = new TeacherExample();
        return teacherMapper.selectByExample(teacherExample);
    }

    @Override
    public void saveOrUpdate(Teacher teacher) {
        if(teacher.getId() != null ){
            teacherMapper.updateByPrimaryKey(teacher);
        }else {
            teacherMapper.insert(teacher);
        }

    }

    @Override
    public void detelateById(long id) {
        checkTeacherExtendMapper.deleteByTeacherId(id);
        teacherMapper.deleteByPrimaryKey(id);

    }

    @Override
    public List<TeacherExtend> findAllWithSubject(Teacher teacher,int pageNum,int limit) {
        PageHelper.startPage(pageNum,limit);
        TeacherExample teacherExample = new TeacherExample();
        List<TeacherExtend> list1 = teacherExtendMapper.selectAllWithSubject();
        PageInfo<TeacherExtend> data = new PageInfo<TeacherExtend>(list1);
        List<TeacherExtend> list = data.getList();
        return list;
    }


    @Override
    public List<TeacherExtend> findWithAllByName(String name, String number,Long subjectId) {
        return teacherExtendMapper.findWithAllByName(name,number,subjectId);
    }
}

